<!DOCTYPE html>






<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />


















  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="vue,axios,nginx,sass,webpack,vuex," />










<meta name="description" content="必备知识点以及涉及知识点  Vue使用基础  EsLint  Sass  Axios  Css3 transform:scale()  Nginx">
<meta name="keywords" content="vue,axios,nginx,sass,webpack,vuex">
<meta property="og:type" content="article">
<meta property="og:title" content="搭建vue开发脚手架">
<meta property="og:url" content="https://zhangyuhan2016.gitee.io/2017/12/15/vue-deploy/index.html">
<meta property="og:site_name" content="zhangyuhan2016">
<meta property="og:description" content="必备知识点以及涉及知识点  Vue使用基础  EsLint  Sass  Axios  Css3 transform:scale()  Nginx">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-04-26T09:37:53.609Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="搭建vue开发脚手架">
<meta name="twitter:description" content="必备知识点以及涉及知识点  Vue使用基础  EsLint  Sass  Axios  Css3 transform:scale()  Nginx">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zhangyuhan2016.gitee.io/2017/12/15/vue-deploy/"/>





  <title>搭建vue开发脚手架 | zhangyuhan2016</title>









</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<header style="position: fixed;z-index: 99999999;background-color: #eee;width: 100%;text-align: center;">
    <h3>感谢您的关注，最新博客已迁移至 <mark style="background-color: #07c160;padding: 4px;"><a style="color: #fff;" href="https://blog.hi-zhang.com" target="_blank">blog.hi-zhang.com</a></mark> </h3>
</header>






  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">


    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">zhangyuhan2016</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>

        <p class="site-subtitle"></p>

  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">



    <ul id="menu" class="menu">


        <li class="menu-item menu-item-home">
          <a href="/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />

            首页
          </a>
        </li>


        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />

            标签
          </a>
        </li>


        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">

              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />

            归档
          </a>
        </li>



    </ul>



</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">


  <div id="posts" class="posts-expand">








  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">



  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zhangyuhan2016.gitee.io/2017/12/15/vue-deploy/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="zhangyuhan2016">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://avatars3.githubusercontent.com/u/18086072?s=460&v=4">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="zhangyuhan2016">
    </span>


      <header class="post-header">



          <h1 class="post-title" itemprop="name headline">搭建vue开发脚手架</h1>


        <div class="post-meta">
          <span class="post-time">

              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>

                <span class="post-meta-item-text">发表于</span>

              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-15T11:27:42+08:00">
                2017-12-15
              </time>



              <span class="post-meta-divider">|</span>



              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>

                <span class="post-meta-item-text">更新于&#58;</span>

              <time title="更新于" itemprop="dateModified" datetime="2018-04-26T17:37:53+08:00">
                2018-04-26
              </time>

          </span>





              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/12/15/vue-deploy/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2017/12/15/vue-deploy/" itemprop="commentCount"></span>
                </a>
              </span>





             <span id="/2017/12/15/vue-deploy/" class="leancloud_visitors" data-flag-title="搭建vue开发脚手架">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>

                 <span class="post-meta-item-text">阅读次数&#58;</span>

                 <span class="leancloud-visitors-count"></span>
             </span>





            <div class="post-wordcount">


                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>

                  <span class="post-meta-item-text">字数统计&#58;</span>

                <span title="字数统计">
                  1,527
                </span>



                <span class="post-meta-divider">|</span>



                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>

                  <span class="post-meta-item-text">阅读时长 &asymp;</span>

                <span title="阅读时长">
                  7
                </span>

            </div>




        </div>
      </header>





    <div class="post-body" itemprop="articleBody">





        <h3 id="必备知识点以及涉及知识点"><a href="#必备知识点以及涉及知识点" class="headerlink" title="必备知识点以及涉及知识点"></a>必备知识点以及涉及知识点</h3><ul>
<li style="list-style: none"><input type="checkbox" checked> Vue使用基础</li>
<li style="list-style: none"><input type="checkbox"> EsLint</li>
<li style="list-style: none"><input type="checkbox"> Sass</li>
<li style="list-style: none"><input type="checkbox"> Axios</li>
<li style="list-style: none"><input type="checkbox"> Css3 transform:scale()</li>
<li style="list-style: none"><input type="checkbox"> Nginx</li>
</ul>
<a id="more"></a>
<p><a href="https://gitee.com/zhangyuhan2016/baseApp" target="_blank" rel="noopener">示例代码</a></p>
<h3 id="vue-cli-3-0"><a href="#vue-cli-3-0" class="headerlink" title="vue@cli 3.0 +"></a>vue@cli 3.0 +</h3><blockquote>
<p>3.0.0-beta.6 版本</p>
<ul>
<li><a href="https://segmentfault.com/a/1190000014094732" target="_blank" rel="noopener">vue-cli 3.0 入门介绍</a></li>
<li><a href="../../../../2018/04/26/vue-cli-3-0/">zhangyuhan2016写的3.0配置指南</a></li>
</ul>
</blockquote>
<h3 id="使用官方vue-cli搭建基本框架"><a href="#使用官方vue-cli搭建基本框架" class="headerlink" title="使用官方vue-cli搭建基本框架"></a>使用官方vue-cli搭建基本框架</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ npm install -g vue-cli</span><br><span class="line">$ vue init webpack my-project</span><br><span class="line">$ cd my-project</span><br><span class="line">$ npm install</span><br><span class="line">$ npm run dev</span><br></pre></td></tr></table></figure>
<h3 id="安装sass预处理"><a href="#安装sass预处理" class="headerlink" title="安装sass预处理"></a>安装sass预处理</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install sass-loader node-sass --save-dev</span><br></pre></td></tr></table></figure>
<h3 id="axios"><a href="#axios" class="headerlink" title="axios"></a><a href="https://github.com/axios/axios" target="_blank" rel="noopener">axios</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install axios --save</span><br></pre></td></tr></table></figure>
<p><a href="https://github.com/axios/axios" target="_blank" rel="noopener">axios</a> 是一个基于Promise 用于浏览器和 nodejs 的 HTTP 客户端,特点：</p>
<ul>
<li>支持Promise API</li>
<li>拦截请求和返回</li>
<li>客户端支持抵御<a href="https://baike.baidu.com/item/CSRF" target="_blank" rel="noopener">XSRF(跨站请求伪造)</a><br><a href="https://segmentfault.com/a/1190000008470355" target="_blank" rel="noopener">中文文档</a><br><a href="https://www.kancloud.cn/yunye/axios/234845" target="_blank" rel="noopener">中文文档2</a></li>
</ul>
<h4 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h4><ol>
<li><p>axios默认是请求的时候不会带上cookie的，需要设置withCredentials参数来解决。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">withCredentials: true</span><br></pre></td></tr></table></figure>
</li>
<li><p>让post使用<strong>formdata</strong>(大多数Ajax的默认数据格式)格式数据<br>默认情况下，axios的Post请求参数为JSON格式。<br>为了发送application/x-wwww-form-urlencoded格式数据,需要使用Qs</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">// 如果使用npm安装的axios则不用额外安装qs</span><br><span class="line">import Qs from &apos;qs&apos;;</span><br><span class="line">var qs = require(&apos;qs&apos;);</span><br><span class="line">axios.post(&apos;/foo&apos;, qs.stringify(&#123;&apos;bar&apos;:123&#125;));</span><br><span class="line"></span><br><span class="line">// 设置Content-Type</span><br><span class="line">axios.defaults.headers.post[&apos;Content-Type&apos;] = &apos;application/x-www-form-urlencoded&apos;;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>带cookie请求</strong><br>axios默认是发送请求的时候不会带上cookie的,需要通过设置<strong>withCredentials: true</strong>来解决.<br>这个时候需要注意需要后端配合设置:<br>header信息 <strong>Access-Control-Allow-Credentials:true</strong><br><strong>Access-Control-Allow-Origin</strong>不可以为<strong>“&#42;”</strong>,因为<strong>“&#42;”</strong>;<br>会和 Access-Control-Allow-Credentials:true 冲突,需配置指定的地址,如果后端设置 Access-Control-Allow-Origin:<strong>“&#42;”</strong>, 会有如下报错信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Failed to load http://localhost:8090/category/lists: The value of the &apos;Access-Control-Allow-Origin&apos; header in the response must not be the wildcard &apos;*&apos; when the request&apos;s credentials mode is &apos;include&apos;. Origin &apos;http://localhost:8081&apos; is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.</span><br></pre></td></tr></table></figure>
</li>
<li><p>可以参考下之前项目中使用的axios配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">import axios from &apos;axios&apos;;</span><br><span class="line">import Qs from &apos;qs&apos;;</span><br><span class="line">const ApiURL = &apos;http://xxxxx.xx&apos;</span><br><span class="line">Vue.prototype.$ajax = axios.create(&#123;</span><br><span class="line">  baseURL: ApiURL,</span><br><span class="line">  timeout: 5000,</span><br><span class="line">  withCredentials: true,</span><br><span class="line"> // 这时候我们通过Qs.stringify转换为表单查询参数</span><br><span class="line">  transformRequest: [function (data) &#123;</span><br><span class="line">    data = Qs.stringify(data);</span><br><span class="line">    return data;</span><br><span class="line">  &#125;],</span><br><span class="line">  // 设置Content-Type</span><br><span class="line">  headers: &#123; &apos;Content-Type&apos;: &apos;application/x-www-form-urlencoded&apos; &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="发布部署问题"><a href="#发布部署问题" class="headerlink" title="发布部署问题"></a>发布部署问题</h3><ol>
<li>服务器根目录把执行<key>npm run build</key>生成的<strong>dist</strong>文件夹（不要上传文件夹）里的内容上传到http服务器上就可以了</li>
<li>服务器子目录修改config/index.js 或者 nginx<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">  build: &#123;</span><br><span class="line">  // Template for index.html</span><br><span class="line">  index: path.resolve(__dirname, &apos;../dist/index.html&apos;),</span><br><span class="line"></span><br><span class="line">  // Paths</span><br><span class="line">  assetsRoot: path.resolve(__dirname, &apos;../dist&apos;),</span><br><span class="line">  assetsSubDirectory: &apos;static&apos;,</span><br><span class="line">  // 只需要修改下面的路径为服务器子目录</span><br><span class="line">  assetsPublicPath: &apos;/res/&apos;,</span><br><span class="line">```  </span><br><span class="line">修改src/router/index.js</span><br><span class="line">```vue</span><br><span class="line">export default new Router(&#123;</span><br><span class="line">// 只需要修改下面的路径为服务器子目录</span><br><span class="line">base: &apos;/res/&apos;,</span><br><span class="line">routes: [</span><br><span class="line">  &#123;</span><br><span class="line">    path: &apos;/&apos;,</span><br><span class="line">    name: &apos;login&apos;,</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="添加缩放"><a href="#添加缩放" class="headerlink" title="添加缩放"></a>添加缩放</h3><p><a href="https://www.zhihu.com/question/47797373" target="_blank" rel="noopener">移动端缩放问题</a></p>
<h4 id="为什么要缩放"><a href="#为什么要缩放" class="headerlink" title="为什么要缩放"></a>为什么要缩放</h4><p>在移动端页面开发中,要适应多种设备的屏幕尺寸,通过使用CSS3缩放,可以让你直接按照设计图的尺寸去还原.<br>当然,你也可以使用其他的解决方案,像rem,em等等</p>
<h4 id="原理"><a href="#原理" class="headerlink" title="原理"></a>原理</h4><p>通过100vw和100vh的Dom来获取可视区域的宽高<br>然后把计算与设计稿的缩放比例<br>把css缩放代码添加到content主内容区</p>
<h3 id="添加meta属性"><a href="#添加meta属性" class="headerlink" title="添加meta属性"></a>添加meta属性</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">// 页面的关键字和描述，作者，是写给搜索引擎看的，关键字可以有多个用 ‘,’号隔开</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"keywords"</span> <span class="attr">content</span>=<span class="string">""</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"description"</span> <span class="attr">content</span>=<span class="string">""</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"author"</span> <span class="attr">content</span>=<span class="string">""</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"</span>&gt;</span></span><br><span class="line">// 禁止浏览器从本地计算机的缓存中访问页面内容</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Expires"</span> <span class="attr">content</span>=<span class="string">"-1"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Cache-Control"</span> <span class="attr">content</span>=<span class="string">"no-cache"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Pragma"</span> <span class="attr">content</span>=<span class="string">"no-cache"</span>&gt;</span></span><br><span class="line">// 全屏显示网页</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"full-screen"</span> <span class="attr">content</span>=<span class="string">"yes"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"x5-fullscreen"</span> <span class="attr">content</span>=<span class="string">"true"</span>&gt;</span></span><br><span class="line">// 强制坚屏显示</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"browsermode"</span> <span class="attr">content</span>=<span class="string">"application"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"x5-orientation"</span> <span class="attr">content</span>=<span class="string">"portrait"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"screen-orientation"</span> <span class="attr">content</span>=<span class="string">"portrait"</span>&gt;</span></span><br><span class="line">// QQ浏览器应用模式</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"x5-page-mode"</span> <span class="attr">content</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"apple-mobile-web-app-capable"</span> <span class="attr">content</span>=<span class="string">"yes"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"apple-mobile-web-app-status-bar-style"</span> <span class="attr">content</span>=<span class="string">"black"</span> /&gt;</span></span><br><span class="line">// ios添加到主屏后的标题</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"apple-mobile-web-app-capable"</span> <span class="attr">content</span>=<span class="string">"yes"</span>&gt;</span></span><br><span class="line">// ios设置工具栏颜色</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"apple-mobile-web-app-status-bar-style"</span> <span class="attr">content</span>=<span class="string">"black"</span>&gt;</span></span><br><span class="line">// 禁止ios点击数字拨号</span><br><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"format-detection"</span> <span class="attr">content</span>=<span class="string">"telephone=no"</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="EsLint规则"><a href="#EsLint规则" class="headerlink" title="EsLint规则"></a>EsLint规则</h3><p>脚手架选用<a href="https://github.com/standard/eslint-config-standard" target="_blank" rel="noopener">JavaScript Standard Style</a></p>
<h3 id="normalize-css"><a href="#normalize-css" class="headerlink" title="normalize.css"></a><a href="https://github.com/necolas/normalize.css/blob/master/normalize.css" target="_blank" rel="noopener">normalize.css</a></h3><p>选用部分<a href="https://github.com/necolas/normalize.css/blob/master/normalize.css" target="_blank" rel="noopener">normalize.css</a>重置样式</p>
<h3 id="API"><a href="#API" class="headerlink" title="API"></a>API</h3><p>通过新建js文件,把所有ajax请求汇总,便于管理<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// config.js</span></span><br><span class="line"><span class="keyword">import</span> axios <span class="keyword">from</span> <span class="string">'axios'</span></span><br><span class="line"><span class="comment">// 配置api地址</span></span><br><span class="line"><span class="keyword">const</span> baseURL = <span class="string">'/api'</span></span><br><span class="line"><span class="comment">// axios设置</span></span><br><span class="line"><span class="keyword">const</span> $ajax = axios.create(&#123;</span><br><span class="line">  baseURL,</span><br><span class="line">  timeout: <span class="number">5000</span>,</span><br><span class="line">  withCredentials: <span class="literal">true</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> $ajax</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// getData.js</span></span><br><span class="line"><span class="keyword">import</span> $ajax <span class="keyword">from</span> <span class="string">'./config'</span></span><br><span class="line"><span class="comment">/* 登陆 */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> login = <span class="function"><span class="params">data</span> =&gt;</span> $ajax.post(<span class="string">'/admin/login'</span>, data)</span><br><span class="line"><span class="comment">/* 注销 */</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> sign = <span class="function"><span class="params">data</span> =&gt;</span> $ajax.post(<span class="string">'/sign'</span>, data)</span><br><span class="line"></span><br><span class="line"><span class="comment">// test.vue</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> &#123; sign &#125; <span class="keyword">from</span> <span class="string">'./getData'</span></span><br><span class="line">sign(<span class="string">'url'</span>).then()</span><br></pre></td></tr></table></figure></p>
<h3 id="本地开发代理请求实现跨域"><a href="#本地开发代理请求实现跨域" class="headerlink" title="本地开发代理请求实现跨域"></a>本地开发代理请求实现跨域</h3><p>通过在<key>config\index.js</key>中进行代理配置,实现跨域</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">module.exports = &#123;</span><br><span class="line">  dev: &#123;</span><br><span class="line"></span><br><span class="line">    // Paths</span><br><span class="line">    assetsSubDirectory: 'static',</span><br><span class="line">    assetsPublicPath: '/',</span><br><span class="line">    proxyTable: &#123;</span><br><span class="line">      '/api': &#123;</span><br><span class="line">        target: 'http://192.168.3.18:88/manager',</span><br><span class="line">        changeOrigin: true,</span><br><span class="line">        pathRewrite: &#123;</span><br><span class="line">          '^/api': ''</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br></pre></td></tr></table></figure>
<p>经过上述配置过后<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$axios.post('/api/goInfo').then()</span><br><span class="line">// 等价下面的代码</span><br><span class="line">$axios.post('http://192.168.3.18:88/manager/goInfo').then()</span><br></pre></td></tr></table></figure></p>
<h3 id="Nginx"><a href="#Nginx" class="headerlink" title="Nginx"></a>Nginx</h3><p>通过配置Nginx可现线上环境的请求代理和vue-router的history模式支持</p>
<ul>
<li>下载Nginx <a href="http://nginx.org/en/download.html" target="_blank" rel="noopener">官网</a></li>
<li><p>修改 <key>conf/nginx.conf </key>文件中 server{} 部分配置</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    listen       1996; # 端口</span><br><span class="line">    server_name  localhost;</span><br><span class="line"></span><br><span class="line">    #charset koi8-r;</span><br><span class="line">    #access_log  logs/host.access.log  main;</span><br><span class="line"></span><br><span class="line">    root E:/Work/Ele/ele/dist; # 映射目录,npm run build后生成的dist</span><br><span class="line"></span><br><span class="line">    location / &#123;</span><br><span class="line">        try_files $uri $uri/ @router; # vue-router history模式配置</span><br><span class="line">        index  index.html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    location ^~/api/ &#123;</span><br><span class="line">     proxy_pass   http://192.168.3.207:88/manager/; # 代理配置</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line">    location @router &#123;</span><br><span class="line">        rewrite ^.*$ /index.html last; # vue-router history模式配置</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    #error_page  404              /404.html;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>运行 nginx.exe ,Shift + 鼠标右键,在目录打开shell命令窗口</p>
</li>
<li>执行 start nginx</li>
<li>其他命令<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">start nginx # 启动</span><br><span class="line">nginx -s stop # 停止</span><br><span class="line">nginx -s quit # 退出</span><br><span class="line">nginx -s reload # 重启</span><br></pre></td></tr></table></figure></li>
</ul>


    </div>







      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">




      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/zfb.png" alt="zhangyuhan2016 支付宝"/>
        <p>支付宝</p>
      </div>




  </div>
</div>

      </div>




    <footer class="post-footer">

        <div class="post-tags">

            <a href="/tags/vue/" rel="tag">vue</a>

            <a href="/tags/axios/" rel="tag">axios</a>

            <a href="/tags/nginx/" rel="tag">nginx</a>

            <a href="/tags/sass/" rel="tag">sass</a>

            <a href="/tags/webpack/" rel="tag">webpack</a>

            <a href="/tags/vuex/" rel="tag">vuex</a>

        </div>







        <div class="post-nav">
          <div class="post-nav-next post-nav-item">

              <a href="/2017/12/14/new-Get/" rel="next" title="new Get">
                <i class="fa fa-chevron-left"></i> new Get
              </a>

          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">

              <a href="/2017/12/29/vue-demo/" rel="prev" title="vue小组件制造之路">
                vue小组件制造之路 <i class="fa fa-chevron-right"></i>
              </a>

          </div>
        </div>




    </footer>
  </div>



  </article>



    <div class="post-spread">

    </div>
  </div>


          </div>






    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>





        </div>



  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">

    <div class="sidebar-inner">




        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>


      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">

              <img class="site-author-image" itemprop="image"
                src="https://avatars3.githubusercontent.com/u/18086072?s=460&v=4"
                alt="zhangyuhan2016" />

              <p class="site-author-name" itemprop="name">zhangyuhan2016</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">


              <div class="site-state-item site-state-posts">

                <a href="/archives/">

                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>







              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">30</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>


          </nav>



          <div class="links-of-author motion-element">


                <span class="links-of-author-item">
                  <a href="https://github.com/zhangyuhan2016" target="_blank" title="GitHub">

                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>


          </div>








        </div>
      </section>


      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">






              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#必备知识点以及涉及知识点"><span class="nav-number">1.</span> <span class="nav-text"><a href="#&#x5FC5;&#x5907;&#x77E5;&#x8BC6;&#x70B9;&#x4EE5;&#x53CA;&#x6D89;&#x53CA;&#x77E5;&#x8BC6;&#x70B9;" class="headerlink" title="&#x5FC5;&#x5907;&#x77E5;&#x8BC6;&#x70B9;&#x4EE5;&#x53CA;&#x6D89;&#x53CA;&#x77E5;&#x8BC6;&#x70B9;"></a>&#x5FC5;&#x5907;&#x77E5;&#x8BC6;&#x70B9;&#x4EE5;&#x53CA;&#x6D89;&#x53CA;&#x77E5;&#x8BC6;&#x70B9;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#vue-cli-3-0"><span class="nav-number">2.</span> <span class="nav-text"><a href="#vue-cli-3-0" class="headerlink" title="vue@cli 3.0 +"></a>vue@cli 3.0 +</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用官方vue-cli搭建基本框架"><span class="nav-number">3.</span> <span class="nav-text"><a href="#&#x4F7F;&#x7528;&#x5B98;&#x65B9;vue-cli&#x642D;&#x5EFA;&#x57FA;&#x672C;&#x6846;&#x67B6;" class="headerlink" title="&#x4F7F;&#x7528;&#x5B98;&#x65B9;vue-cli&#x642D;&#x5EFA;&#x57FA;&#x672C;&#x6846;&#x67B6;"></a>&#x4F7F;&#x7528;&#x5B98;&#x65B9;vue-cli&#x642D;&#x5EFA;&#x57FA;&#x672C;&#x6846;&#x67B6;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装sass预处理"><span class="nav-number">4.</span> <span class="nav-text"><a href="#&#x5B89;&#x88C5;sass&#x9884;&#x5904;&#x7406;" class="headerlink" title="&#x5B89;&#x88C5;sass&#x9884;&#x5904;&#x7406;"></a>&#x5B89;&#x88C5;sass&#x9884;&#x5904;&#x7406;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#axios"><span class="nav-number">5.</span> <span class="nav-text"><a href="#axios" class="headerlink" title="axios"></a><a href="https://github.com/axios/axios" target="_blank" rel="noopener">axios</a></span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#常见问题"><span class="nav-number">5.1.</span> <span class="nav-text"><a href="#&#x5E38;&#x89C1;&#x95EE;&#x9898;" class="headerlink" title="&#x5E38;&#x89C1;&#x95EE;&#x9898;"></a>&#x5E38;&#x89C1;&#x95EE;&#x9898;</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#发布部署问题"><span class="nav-number">6.</span> <span class="nav-text"><a href="#&#x53D1;&#x5E03;&#x90E8;&#x7F72;&#x95EE;&#x9898;" class="headerlink" title="&#x53D1;&#x5E03;&#x90E8;&#x7F72;&#x95EE;&#x9898;"></a>&#x53D1;&#x5E03;&#x90E8;&#x7F72;&#x95EE;&#x9898;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#添加缩放"><span class="nav-number">7.</span> <span class="nav-text"><a href="#&#x6DFB;&#x52A0;&#x7F29;&#x653E;" class="headerlink" title="&#x6DFB;&#x52A0;&#x7F29;&#x653E;"></a>&#x6DFB;&#x52A0;&#x7F29;&#x653E;</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#为什么要缩放"><span class="nav-number">7.1.</span> <span class="nav-text"><a href="#&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7F29;&#x653E;" class="headerlink" title="&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7F29;&#x653E;"></a>&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x7F29;&#x653E;</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#原理"><span class="nav-number">7.2.</span> <span class="nav-text"><a href="#&#x539F;&#x7406;" class="headerlink" title="&#x539F;&#x7406;"></a>&#x539F;&#x7406;</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#添加meta属性"><span class="nav-number">8.</span> <span class="nav-text"><a href="#&#x6DFB;&#x52A0;meta&#x5C5E;&#x6027;" class="headerlink" title="&#x6DFB;&#x52A0;meta&#x5C5E;&#x6027;"></a>&#x6DFB;&#x52A0;meta&#x5C5E;&#x6027;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#EsLint规则"><span class="nav-number">9.</span> <span class="nav-text"><a href="#EsLint&#x89C4;&#x5219;" class="headerlink" title="EsLint&#x89C4;&#x5219;"></a>EsLint&#x89C4;&#x5219;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#normalize-css"><span class="nav-number">10.</span> <span class="nav-text"><a href="#normalize-css" class="headerlink" title="normalize.css"></a><a href="https://github.com/necolas/normalize.css/blob/master/normalize.css" target="_blank" rel="noopener">normalize.css</a></span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#API"><span class="nav-number">11.</span> <span class="nav-text"><a href="#API" class="headerlink" title="API"></a>API</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#本地开发代理请求实现跨域"><span class="nav-number">12.</span> <span class="nav-text"><a href="#&#x672C;&#x5730;&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x8BF7;&#x6C42;&#x5B9E;&#x73B0;&#x8DE8;&#x57DF;" class="headerlink" title="&#x672C;&#x5730;&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x8BF7;&#x6C42;&#x5B9E;&#x73B0;&#x8DE8;&#x57DF;"></a>&#x672C;&#x5730;&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x8BF7;&#x6C42;&#x5B9E;&#x73B0;&#x8DE8;&#x57DF;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx"><span class="nav-number">13.</span> <span class="nav-text"><a href="#Nginx" class="headerlink" title="Nginx"></a>Nginx</span></a></li></ol></div>


          </div>
        </section>
      <!--/noindex-->




    </div>
    <div class="post-block page my-thanks">
        <div class="my-title">致谢</div>
        <div class="thanks">Hexo</div>
        <div class="thanks">Next & Gemini</div>
        <div class="thanks">Gitee</div>
    </div>
  </aside>



      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">









      </div>
    </footer>


      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>

      </div>




  </div>



<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>



























    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>




    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>




    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>




    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>




    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>




    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>




    <script type="text/javascript" src="/lib/three/three.min.js"></script>




    <script type="text/javascript" src="/lib/three/canvas_lines.min.js"></script>






  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>







  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>




  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>






  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>









      <script id="dsq-count-scr" src="https://.disqus.com/count.js" async></script>



      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://zhangyuhan2016.gitee.io/2017/12/15/vue-deploy/';
          this.page.identifier = '2017/12/15/vue-deploy/';
          this.page.title = '搭建vue开发脚手架';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>






























  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>

  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: true,
        notify: false,
        appId: 'xxTmc7jwpAd2bWhmkKOI7IGY-gzGzoHsz',
        appKey: 'glPUiD8ljbJsKYhBg5E0ghII',
        placeholder: '说点什么呗 ヾﾉ≧∀≦)o',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>












  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("mpOMyFHLi7a5S0ka5mv3cz7C-gzGzoHsz", "3t0W0au9Mxf0lOGFDF8u89pc");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>
















</body>
</html>
